<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/list.css">
</head>

<body>
    <div class="center">
        <h2>英雄列表</h2>
        <button>点击获取所有LOL英雄</button>
        <div class="box">

        </div>
    </div>


    <script>
        let btn = document.querySelector("button")

        btn.onclick = function () {
            let x = new XMLHttpRequest()
            x.open("get", "http://localhost/getHeros")
            x.send()
            x.responseType = "json"
            
            x.onreadystatechange = function () {
                if (x.readyState === 4 && x.status === 200) {
                    let res = x.response
                    let str = ``
                    res.forEach(item => {
                        str += `<div class="list">
                                <img src="${item.avatar}" alt="">
                                <p>${item.name}</p>
                            </div>`
                    });
                    let box = document.querySelector(".box")
                    box.innerHTML = str
                    
                }
            }
        }
    </script>
</body>

</html>